//
//  SchoolVC.m
//  BrushFace
//
//  Created by Harry on 16/1/27.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "SchoolVC.h"
#import "SchoolSubVC.h"
@interface SchoolVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation SchoolVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navBar setTitle:@"学历学籍"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    _dataArray = [NSMutableArray array];
    NSString *path = [[NSString alloc]init];
    
    if (_SCHOOLTYPE == SCHOOLTYPE_school)
    {
        path = [[NSBundle mainBundle]pathForResource:@"college" ofType:@"json"];
    }
    else if (_SCHOOLTYPE == SCHOOLTYPE_adress)
    {
        path = [[NSBundle mainBundle]pathForResource:@"address" ofType:@"json"];
    }
        NSData *data = [[NSData alloc]initWithContentsOfFile:path];;
    id jsondata = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSArray *array = (NSArray *)jsondata;
    [_dataArray addObjectsFromArray:array];
    _tableView.delegate = self;
    _tableView.dataSource =self;
    [_tableView reloadData];
}

//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//{
//    NSDictionary *dic = _dataArray[section];
//    return dic[@"indexs"];
//}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *cellName = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
        
    }
    
    NSDictionary *dic = _dataArray[indexPath.section];
   
    cell.textLabel.text = dic[@"name"];
    
    
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSDictionary *datadic = _dataArray[indexPath.section];
    SchoolSubVC *subVC = [[SchoolSubVC alloc]init];
    if (_SCHOOLTYPE == SCHOOLTYPE_school)
    {
        
        subVC.SCHOOLSUBTYPE = SCHOOLTYPE_school;
        subVC.proName= datadic[@"name"];
    }
    else
    {
        subVC.SCHOOLSUBTYPE = SCHOOLTYPE_adress;
         subVC.proName= datadic[@"name"];
    }
    NSDictionary *dic = _dataArray[indexPath.section];
    subVC.dataArray = dic[@"items"];
    [self.navigationController pushViewController:subVC animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
